"""
内容:搜索内容根据价格,正序排序搜索
作者:刘芳
"""
#引入模块
from ECshop.common.base import Base,create_browser_op
import time
#创建类

class PageDropDown(Base):
    #定义属性
    url="http://localhost:8080/ecshop/search.php?encode=YTozOntzOjg6ImtleXdvcmRzIjtzOjA6IiI7czoxMDoiaW1hZ2VGaWVsZCI7czo2OiLmkJzntKIiO3M6MTg6InNlYXJjaF9lbmNvZGVfdGltZSI7aToxNjU3MTAzNzQzO30="
    price=("name","sort")
    text1='按价格排序'
    sort=("name","order")
    text2="正序"
    go = ("xpath", "//input[@src='themes/default/images/bnt_go.gif']")
    image_text = ("css selector", "img[src='themes/default/images/display_mode_list.gif']")
    good_price1=("xpath","//form[@id='compareForm']/div/ul[1]/li[4]/font")
    good_price2=("xpath","//form[@id='compareForm']/div/ul[2]/li[4]/font")
    #定义方法
    #打开网页
    def page_drop_down_open_web(self):
        self.base_open_web(self.url)

    #点击图文展示方式
    def page_drop_down_image_text(self):
        self.base_click(self.image_text)


    #点击下拉框选择按价格排序
    def page_drop_down_select1(self):
        self.base_select(self.price,self.text1)

    #点击正序
    def page_drop_down_select2(self):
        self.base_select(self.sort,self.text2)
    #点击go
    def page_drop_down_click(self):
        self.base_click(self.go)
    #退出
    def page_drop_down_quit(self):
        self.base_quit()

    #获取第一个商品价格
    def page_drop_down_get_text(self):
        return self.base_get_text(self.good_price1)
    #获取第二个商品价格
    def page_drop_down_get_text1(self):
        return self.base_get_text(self.good_price2)
    #获取第二个商品价格




if __name__ == '__main__':
        pc1=PageDropDown(create_browser_op(r'C:\Users\86184\AppData\Local\Google\Chrome\User Data'))
        # time.sleep(1)
        pc1.page_drop_down_open_web()
        time.sleep(3)
        # time.sleep(1)
        pc1.page_drop_down_image_text()
        pc1.page_drop_down_select1()
        time.sleep(3)
        pc1.page_drop_down_select2()
        pc1.page_drop_down_click()
        time.sleep(3)
        print(pc1.page_drop_down_get_text())
        print(pc1.page_drop_down_get_text1())
        pc1.page_drop_down_quit()